package com.nexgo.payment.trans.setting.terminalkey.bccdownkey;

import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import com.nexgo.payment.R;
import com.nexgo.payment.databases.Repository;
import com.nexgo.payment.trans.setting.terminalkey.downkey.DownloadKeyContract;
import com.nexgo.payment.ui.BaseActivity;
import com.nexgo.payment.util.UIUtils;
import com.nexgo.payment.widget.TitleBuilder;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by wzp on 2018/1/9.
 */

public class BccDownloadKeyActivity extends BaseActivity implements BccDownloadKeyContract.View {
    @BindView(R.id.tv_desc)
    TextView tvDesc;

    private BccDownloadKeyContract.Presenter mPresenter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_bcc_download_key);
        ButterKnife.bind(this);

        initTitle();

        new BccDownloadKeyPresenter(getApplicationContext(), this, Repository.getInstance());
    }

    /**
     * 初始化标题
     */
    private void initTitle() {
        new TitleBuilder(this)
                .setExternalTitleBgRes(R.drawable.bg_blue_icon)
                .setLeftImage(R.drawable.arrow_icon)
                .setTitleText(getString(R.string.download_master_key))
                .build();
    }


    @OnClick({R.id.title_iv_left, R.id.btn_cancel,R.id.btn_confirm})
    public void onClicked(View view) {
        if (UIUtils.isDoubleClick()){
            return;
        }
        switch (view.getId()) {
            case R.id.title_iv_left:
            case R.id.btn_cancel:
                finish();
                break;
            case R.id.btn_confirm:
                if (mPresenter != null) mPresenter.start();
                break;
            default:
                break;
        }
    }

    @Override
    public void showSuccessful() {
        tvDesc.setText(getString(R.string.import_key_success));
        finish();
    }

    @Override
    public void showFail() {
        tvDesc.setText(getString(R.string.import_key_fail));
        finish();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        if (mPresenter != null) {
            mPresenter.destroy();
        }
    }

    @Override
    public void setPresenter(BccDownloadKeyContract.Presenter presenter) {
        mPresenter = presenter;
    }
}
